-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix flake: clarify error message when file is an unknown type #12167
base: master
Are you sure you want to change the base?
nix flake: clarify error message when file is an unknown type #12167
Conversation
992ead7
to
ad7111c
Compare
src/nix/flake.cc
Outdated
@@ -941,7 +941,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand | |||
createSymlink(target, os_string_to_string(PathViewNG { to2 })); | |||
} | |||
else | |||
throw Error("file '%s' has unsupported type", from2); | |||
throw Error("path '%s' is not either a symlink, file, or directory but a %s", from2, st.typeString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw Error("path '%s' is not either a symlink, file, or directory but a %s", from2, st.typeString()); | |
throw Error("path '%s' needs to be a symlink, file, or directory but instead is a %s", from2, st.typeString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ad7111c
to
bbf2efc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I have a slight hesitation about adding non-NAR-legal types to SourceAccessor
, because it's supposed to represent the NAR view of the file system. But then again, it already had a tMisc
type so this doesn't really change anything.
case SourceAccessor::tChar: | ||
case SourceAccessor::tBlock: | ||
case SourceAccessor::tSocket: | ||
case SourceAccessor::tFifo: | ||
case SourceAccessor::tUnknown: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case SourceAccessor::tChar: | |
case SourceAccessor::tBlock: | |
case SourceAccessor::tSocket: | |
case SourceAccessor::tFifo: | |
case SourceAccessor::tUnknown: |
We can just rely on the default case here (everything is unsupported except for the types handled above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get an error saying not all the cases are met when I remove it.
src/libutil/git.cc
Outdated
case SourceAccessor::tBlock: | ||
case SourceAccessor::tSocket: | ||
case SourceAccessor::tFifo: | ||
case SourceAccessor::tUnknown: | ||
default: | ||
throw Error("file '%1%' has an unsupported type", path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw Error("file '%1%' has an unsupported type", path); | |
throw Error("file '%1%' has an unsupported type", path); |
This can use typeString()
now to show the type of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/libutil/source-accessor.cc
Outdated
@@ -5,6 +5,25 @@ namespace nix { | |||
|
|||
static std::atomic<size_t> nextNumber{0}; | |||
|
|||
bool SourceAccessor::Stat::isTypeUnknown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool SourceAccessor::Stat::isTypeUnknown() { | |
bool SourceAccessor::Stat::isTypeUnknown() | |
{ |
Formatting nitpick.
isTypeUnknown()
is a misnomer since we do know the type now. Maybe it should be something like isNotNARSerialisable()
to denote that it's a type than isn't supported in a NAR file. (Or isNARSerialisable()
to avoid the negation.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I did try clang-format
but then it formatted every single file. It seems nix hasn't followed clang-format for some time?
bbf2efc
to
22adffe
Compare
Motivation
Clarify the error as seen in #11217
Context
#11217 is where this behavior has been seen
Simply clarifying the error makes the user know why the failure occurred.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.